// 数据库相关信息元数据
import {
    alignData,
    BooleanData,
    dbFieldIndex,
    dbFieldType,
    primaryType, SelectionRowData, sortData,
    tableFixedData
} from "@/components/OptionsMetaData";
import Utils from "@/utils/basic.utils";
import {EventBus, EventType} from "@/event";

/**
 * 数据库表信息元数据
 * @type {({field: string, rules: [{message: string, required: boolean}], placeholder: string, title: string, type: string}|{field: string, change: change, placeholder: string, title: string, type: string}|{field: string, rules: [{message: string, required: boolean}], title: string, type: string}|{field: string, data: [{label: string, value: string}, {label: string, value: string}, {label: string, value: string}], title: string, type: string, radioStyle: string}|{field: string, data: [{children: [{label: string, value: string}, {label: string, value: string}], label: string, value: string}], title: string, type: string})[]}
 */
const tableMetas = [
    {field: 'tableName', title: '表名', type: 'text', rules: [{required: true, message: '表名必填'}], placeholder: '数据库表名(t_user)'},
    {field: 'comment', title: '表说明', type: 'text', placeholder: '数据库表说明(会员表)'},
    {field: 'keyField', title: '主键字段', type: 'text', default: 'id', extra: '为空则不加入sql脚本'},
    {field: 'keyType', title: '主键类型', type: 'radio',
        data: primaryType, radioStyle: 'button', default: 'bigint'},
]
/**
 * 数据库表字段元数据
 * @type {({field: string, rules: [{message: string, required: boolean}], placeholder: string, title: string, type: string}|{lengthDisabled: boolean, field: string, data, change: change, lengthField: string, rules: [{message: string, required: boolean}], title: string, type: string}|{field: string, data, change: change, title: string, type: string})[]}
 */
const tableFieldMetas = [
    {field: 'desc', title: '表字段配置', type: 'divider'},
    {field: 'name', title: '表字段', type: 'text', rules: [{required: true, message: ''}]
        , placeholder: '表字段名(user_name)', change(val, meta, model) {
            model['entityField'] = Utils.toHump(val);
        }},
    {field: 'fieldType', title: '字段类型', type: 'fieldType', data: dbFieldType
        , lengthField: 'typeLength', lengthDisabled: false, rules: [{required: true, message: '字段类型必填'}]
        , change: (val, meta, model)=>{}
    },

    {field: 'otherType', title: '字段约束', type: 'checkbox'
        , data: dbFieldIndex, change: (val, meta, model)=>{
            if(val.includes('unique')) {
                model['unique'] = true;
            } else {
                model['unique'] = false;
            }
            if(val.includes('index')) {
                model['index'] = true;
            } else {
                model['index'] = false;
            }
        }},
]



export {tableMetas, tableFieldMetas}
